package com.xxxt.zpc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xxxt.dao.InformMapper;
import com.xxxt.entity.Inform;
import com.xxxt.entity.Teacher;
import com.xxxt.utils.DateUtil;
import com.xxxt.utils.UUIDUtil;
import com.xxxt.zpc.service.InformService;

@Service
public class InformServiceImpl implements InformService {

	@Autowired
	InformMapper informMapper;

	@Override
	public Boolean insertInform(String title, String content,String account) {
		Teacher teacher = new Teacher();
		Inform inform = new Inform();
		inform.setInformId(UUIDUtil.getUUID());
		inform.setTitle(title);
		inform.setContent(content);
		teacher.setTno(account);
		inform.setTeacher(teacher);
		inform.setPublishTime(DateUtil.getDate());
		if(title==null||content==null) return false;
		boolean result=false;
		try{
			result= informMapper.insertInform(inform);
		}catch(Exception e){
			return false;
		}
		return result;
	}

	@Override
	public Inform selectInformById(String informID) {
		return informMapper.selectInformById(informID);
	}

	@Override
	public Boolean deleteInformById(String informID,String account) {
		return informMapper.deleteInformById(informID,account);
	}


	@Override
	public List<Inform> selectInformIdByTnoBySno(String sno) {

		return informMapper.selectInformByTnoBySno(sno);
	}

	@Override
	public List<Inform> selectInformByTno(String tno) {
		
		return informMapper.selectInformByTno(tno);
	}

	@Override
	public Boolean updateInformById(String informId, String title, String content,String account) {
		if(informId==null||title==null||content==null){
			return false;
		}
		return informMapper.updateInformById(informId, title, content,account);
	}

	@Override
	public List<String> selectInformIdBySno(String sno) {
		
		return informMapper.selectInformBySno(sno);
	}

	@Override
	public Inform selectInformByIda(String informID) {
		
		return informMapper.selectInformByIda(informID);
	}

	@Override
	public boolean deleteInformByIdList(List<String> array, String tno) {
		if(tno!=null&&array.size()>0){
			try{
				boolean r=informMapper.deleteInformByIdList(array, tno);
				return r;
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		return false;
	}

}
